package Java8实战._2_Stream_使用流._2_映射;

import java.util.Arrays;
import java.util.List;


public class _3_测试2 {

    public static void main(String[] args) {

        /**
         * 二维数据
         */
//        int [][] arr = {{1,2},{2,3,4},{3,4,5,6}};
//
//        for (int i = 0; i < arr.length; i++){
//            for (int j = 0; j < arr[i].length; j++){
//                System.out.print(arr[i][j] + "\t");
//            }
//        }

        List<Integer> list1 = Arrays.asList(1,2,3);
        List<Integer> list2 = Arrays.asList(3,4);

        //==============================
        //map 与 flatMap 返回值对比 -start
        //==============================
//        Stream<Stream<int[]>> streamStream = list1.stream()
//                .map(i -> list2.stream()
//                        .map(j -> new int[]{i, j})
//                );


//        Stream<int[]> stream = list1.stream()
//                .flatMap(i -> list2.stream()
//                        .map(j -> new int[]{i, j})
//                );

        //==============================
        //map 与 flatMap 返回值对比 -end
        //=============================

        list1.stream()
                .flatMap(i -> list2.stream()
                        .map(j -> new int[]{i,j})
                )
                .forEach(x -> {
                            System.out.print("(");
                            for (int i = 0; i < x.length; i++) {
                                System.out.print(x[i]);
                                if(i != x.length -1){
                                    System.out.print(",");
                                }
                            }
                            System.out.print("),");
                        }
                );
    }
}
